import random
import cv2
import numpy as np
train_lines=open('train.txt','r',encoding='utf-8').readlines()
random.shuffle(train_lines)
val_lines=open('val.txt','r',encoding='utf-8').readlines()
random.shuffle(val_lines)

x_train=[]
y_train=[]
for lin in train_lines:
    path=lin.strip().rsplit(None,1)[0]
    lab=lin.strip().rsplit(None,1)[1]
    img=cv2.imdecode(np.fromfile(path,dtype=np.uint8),-1)
    img=cv2.resize(img,(64,64))
    x_train.append(img)
    y_train.append(int(lab))

x_train=np.array(x_train)
y_train=np.array(y_train)
np.save('data/x_train.npy',x_train)
np.save('data/y_train.npy',y_train)

x_train=[]
y_train=[]
for lin in val_lines:
    path=lin.strip().rsplit(None,1)[0]
    lab=lin.strip().rsplit(None,1)[1]
    img=cv2.imdecode(np.fromfile(path,dtype=np.uint8),-1)
    img=cv2.resize(img,(64,64))
    x_train.append(img)
    y_train.append(int(lab))

x_train=np.array(x_train)
y_train=np.array(y_train)
np.save('data/x_val.npy',x_train)
np.save('data/y_val.npy',y_train)


print(123)